﻿#include "uidevicemanage.h"

#include <QPushButton>
#include <QPainter>

#include <shlib/quc_sdk/panelwidget/panelwidget.h>
#include <shlib/quc_sdk/iconhelper/icon_helper.h>


UiDeviceManage::UiDeviceManage(QWidget *parent)
    : QWidget{parent}
{
    initUi();
    initData();
}

void UiDeviceManage::initUi()
{
    IconHelper* iconsMgr = IconHelper::instance();

    QFrame* farme = new QFrame(this);

    m_newSceneBtn = new QPushButton("新建场景",farme);
    m_newSceneBtn->setObjectName("scene_manager_btn");
    m_newSceneBtn->setMinimumSize(90, 25);
    m_newSceneBtn->setStyleSheet("QPushButton { background-color: #1e3050; border: none; border-radius: 6px; color: white;}");
    m_newSceneBtn->setIconSize(QSize(25,25));
    m_newSceneBtn->setIcon(QIcon(iconsMgr->getPixmap(QColor::fromString("#63E6BE"), IconHelper::FontAwesome6Solid, 0xf5ff, 22, 25,25)));

    m_refreshSceneBtn = new QPushButton("刷新模型",farme);
    m_refreshSceneBtn->setObjectName("scene_manager_btn");
    m_refreshSceneBtn->setStyleSheet("QPushButton { background-color: #1e3050; border: none; border-radius: 6px; color: white;}");
    m_refreshSceneBtn->setIconSize(QSize(25,25));
    m_refreshSceneBtn->setMinimumSize(90, 25);
    m_refreshSceneBtn->setIcon(QIcon(iconsMgr->getPixmap(QColor::fromString("#63E6BE"), IconHelper::FontAwesome6Solid, 0xf2f9, 19, 25,25)));

    QHBoxLayout* btnLayout = new QHBoxLayout();
    btnLayout->setContentsMargins(0,0,0,40);
    btnLayout->addStretch(1);
    btnLayout->addWidget(m_newSceneBtn);
    btnLayout->addWidget(m_refreshSceneBtn);
    btnLayout->addStretch(0);

    farme->setLayout(btnLayout);
    farme->setFixedHeight(30);

    m_view = new PanelWidget;

    m_mainLayout = new QVBoxLayout(this);
    m_mainLayout->addWidget(farme);
    m_mainLayout->addWidget(m_view);
}

void UiDeviceManage::initData() {
    qDebug() << "width = " << m_view->width();
    QList<QWidget *> widgets2;
    for (int i = 1; i <= 200; i++) {
        CRtDeviceInfo dev;
        UiDeviceInfoCard *frm = new UiDeviceInfoCard(dev);
        frm->setFixedHeight(90);
        frm->setMinimumWidth(259);
        frm->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
        widgets2.append(frm);
    }

    m_view->setWidget(widgets2, 6);
    m_view->setMargin(1);
    m_view->setSpace(3);
    m_view->setAutoWidth(true);
}

void UiDeviceManage::paintEvent(QPaintEvent *event) {
    QPainter painter(this);
    QColor lightBlue(249, 249, 252);

    QPainterPath path;
    path.addRoundedRect(rect(), 10, 10); // 圆角半径为10
    painter.fillPath(path, lightBlue);
}
